//package com.cc.controller;
//
//import com.cc.domain.User;
//import com.cc.service.UserService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.ResponseEntity;
//import org.springframework.util.concurrent.ListenableFuture;
//import org.springframework.util.concurrent.ListenableFutureCallback;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.client.AsyncRestTemplate;
//
//import java.util.concurrent.Callable;
//
//@RestController
//public class UserController {
//    private UserService userService;
//
//    @Autowired
//    public UserController(UserService userService) {
//        this.userService = userService;
//    }
//
//    @RequestMapping("/api")
//    public Callable<User> api() {
//        System.out.println("=====hello");
//        return new Callable<User>() {
//            @Override
//            public User call() throws Exception {
//                Thread.sleep(10L * 1000); //暂停两秒
//                User user = new User();
//                user.setUid(1);
//                user.setName("haha");
//                return user;
//            }
//        };
//    }
//
//    public static void main(String[] args) {
//        AsyncRestTemplate template = new AsyncRestTemplate();
//        //调用完后立即返回（没有阻塞）
//        ListenableFuture<ResponseEntity<User>> future = template.getForEntity("http://localhost:9080/spring4/api", User.class);
//        //设置异步回调
//        future.addCallback(new ListenableFutureCallback<ResponseEntity<User>>() {
//            @Override
//            public void onSuccess(ResponseEntity<User> result) {
//                System.out.println("======client get result : " + result.getBody());
//            }
//
//            @Override
//            public void onFailure(Throwable t) {
//                System.out.println("======client failure : " + t);
//            }
//        });
//        System.out.println("==no wait");
//    }
//}